<?php $this->headScript()->appendFile($this->js('plugins/jquery.selectboxes.js'))
->appendFile($this->js('plugins/jquery.blockUI.js'))
->appendFile($this->js('plugins/jquery.alerts.js'));
$this->headLink()->appendStylesheet($this->js('css/jquery.alerts.css'))
->appendStylesheet($this->Css('table.css'));
?>
<script>
function changeStep()
{
	var act = $("input[name='act']:checked").val();
	$.getJSON("<?php echo $this->route('get-semester-options')?>",{act:act},function(data){
		   $("#source_semester").removeOption(/./);
           //$("#source_semester").addOption('','<?php echo $this->translate("select course")?>');
           $("#source_semester").addOption(data.all, false);
	    if (data.current) {
		    $("#copyBtn").addClass('ui-state-disabled').attr('disabled','disabled');
		    $("#deleteBtn").removeClass('ui-state-disabled').attr('disabled','');
		    $("#current-message").html('<?php echo $this->translate("current semester data total:")?>'+data.current.cc);
	    }
	    else {
	    	$("#copyBtn").removeClass('ui-state-disabled').attr('disabled','');
	    	$("#deleteBtn").addClass('ui-state-disabled').attr('disabled','disabled');
	    	$("#current-message").html('');
	    }
	});
}

$(document).ready(function(){
  changeStep();

  $("input[name='act']").change(changeStep);
  $("#copyBtn").click(function(){
	  var source_semester = $("#source_semester").val();
	  var act = $("input[name='act']:checked").val();
	  $("body").block({message:'<h1><?php echo $this->translate("copying ..")?></h1>',  border: '3px solid #a00' });
	  $.get('<?php echo $this->route("copy")?>',{semester:source_semester, act:act}, function(data){
		  changeStep();
		  $("body").unblock();
	  });
   });

  $("#deleteBtn").click(function(){
	  jConfirm('<?php echo $this->translate("Can you confirm this?")?>', '<?php echo $this->translate("Confirmation Dialog")?>', function(r) {
		    if (r) {
		    	var act = $("input[name='act']:checked").val();
		    	$.get('<?php echo $this->route("delete")?>',{act:act}, function(data){
		    		changeStep();
			    });
		    }
		});


  });

});
</script>
<style>
.hor-minimalist-a {margin:auto; white-space:nowrap; width:800px; text-align:center }
#current-message {margin:5px; background:#ffa;padding:2px;}
</style>
<table class="hor-minimalist-a">
<thead>
<tr>
<th><?php echo $this->translate('item')?></th>
<th><?php echo $this->translate('from source semester')?></th>
<th><?php echo $this->translate('copy to semester')?></th>
<th><?php echo $this->translate('copy action')?></th>
<th><?php echo $this->translate('delete action')?></th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="radio" name="act" value="class_set"  id="class_set"  checked="checked"/>
<label for="class_set"><?php echo $this->translate('Class Set')?></label>
</td>
<td rowspan="6" style="vertical-align: top;">
<select id="source_semester" name="source_semester" ></select>
</td>
<td rowspan="6" style="vertical-align: top;">
<?php echo sprintf($this->translate('%d No. %d academic year semester'),$this->Semester['year'], $this->Semester['semester'])?>
</td>
<td rowspan="6" style="vertical-align: top;">
<button id="copyBtn" class="ui-state-default ui-corner-all" type="submit"><?php echo $this->translate('copy')?></button>
</td>
<td rowspan="6" style="vertical-align: top;">
<button id="deleteBtn" class="ui-state-default ui-corner-all" type="submit"><?php echo $this->translate('delete')?></button>
<div id="current-message"></div>
</td>
</tr>
<tr>
<td><input type="radio" name="act" value="score_setup"  id="score_setup" />
<label for="score_setup"><?php echo $this->translate('score setup')?></label>
</td>
</tr>
<tr>
<td><input type="radio" name="act" value="course_setup"  id="course_setup"/>
<label for="course_setup"><?php echo $this->translate('course setup')?></label>
</td>
</tr>
<tr>
<td><input type="radio" name="act" value="teacher_setup"  id="teacher_setup"/>
<label for="teacher_setup"><?php echo $this->translate('teacher setup')?></label>
</td>
</tr>
<tr>
<td><input type="radio" name="act" value="section_setup"  id="section_setup"/>
<label for="section_setup"><?php echo $this->translate('Timetable setup')?></label>
</td>
</tr>
<tr>
<td><input type="radio" name="act" value="tutor_setup"  id="tutor_setup"/>
<label for="tutor_setup"><?php echo $this->translate('tutor setup')?></label>
</td>
</tr>

</tbody>
</table>